<?php


namespace app\middleware;

function parseBool($val)
{
    if ($val === 'true') {
        return true;
    }
    if ($val === 'false') {
        return false;
    }
    return $val;
}

class String2Bool
{
    public function handle($request, \Closure $next)
    {
        if ($request->isGet())
        {
            $param = $request->param();
            foreach ($param as $key => $value)
            {
                $param[$key] = parseBool($value);
            }

            $request->withGet($param);
        }
        return $next($request);
    }
}